import Net from 'network.js'

/**
 * 获取团队成员列表
 * 
 */
export const getTeamList = (team_id, state, callback) => {
  Net.get('/team/users', {
    team_id,
    state
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '')
}

/**
 * 登录
 * 
 */
export const login = (jscode, iv, encryptData, userinfo, callback) => {
  Net.get('/user/login', {
    jscode,
    iv,
    encryptData,
    userinfo
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '登录中...')
}

/**
 * 生成邀请团队成员太阳码
 * 
 */
export const getInviteCode = (team_id, callback) => {
  Net.get('/team/invite_code', {
    team_id
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '获取中...')
}

/**
 * 商户个人中心初始化
 * 
 */
export const getInit = (callback) => {
  Net.get('/user/user', {}, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
}


/**
 * 创建团队
 * 
 */
export const createTeam = (nick_name, callback) => {
  Net.post('/team/team', {
    nick_name
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '创建中...')
}

/**
 * 审核团队成员
 * opt 1同意 2拒绝
 * 
 */
export const auditing = (opt, member_id, team_id, callback) => {
  Net.post('/team/user/conform', {
    opt,
    member_id,
    team_id
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '操作中...')
}


/**
 * 获取代理，供应商列表
 * ptype 1代理 2供应商
 * team_id
 * 
 */
export const getproxyList = (ptype, team_id, callback) => {
  Net.get('/proxy/proxies', {
    ptype,
    team_id
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
}


/**
 * 获取代理，供应商邀请码
 * invite_type=2代理 3供应商
 * 
 */
export const getProxyCode = (team_id, invite_type, callback) => {
  Net.get('/proxy/invite_code', {
    team_id,
    invite_type,
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
}


/**
 * 删除团队成员 
 * 
 */
export const memberDel = (member_id, callback) => {
  Net.post('/team/user_del', {
    member_id
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '操作中...')
}


/**
 * 解散团队 
 * 
 */
export const teamDel = (callback) => {
  Net.post('/team/team_del', {}, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '操作中...')
}

/**
 * 退出团队 
 * 
 */
export const teamQuit = (callback) => {
  Net.post('/team/user/quit', {}, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '操作中...')
}




/**
 * 申请加入团队 
 * 
 */
export const joinTeam = (i, t, callback) => {
  Net.post('/team/join', {
    i,
    t
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
}

/**
 * 获取申请加入团队信息 
 * 
 */
export const getJoinTeamInfo = (i, t, callback) => {
  Net.get('/team/join', {
    i,
    t
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
}
/**
 * 获取加入代理，供应商的邀请页面信息 
 * 
 */
export const getProxyJoin = (i, t, callback) => {
  Net.get('/proxy/join', {
    i,
    t
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
}


/**
 * 申请成为代理，供应商 
 * 
 */
export const subProxyJoin = (i, t, callback) => {
  Net.post('/proxy/join', {
    i,
    t
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
}


/**
 * 注册 
 */
export const registerSubmit = (name, mobile, verifyCode, i, t, action, callback) => {
  Net.post('/user/regist', {
    name,
    mobile,
    verifyCode,
    i,
    t,
    action
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
}


/**
 * 删除代理商  供应商 
 */
export const proxyDel = (id, t, callback) => {
  Net.post('/proxy/del', {
    id,
    t
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '操作中...')
}



/**
 * 供应商列表
 *  
 */
export const proxySuppliers = (callback) => {
  Net.get('/proxy/suppliers', {}, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
}



/**
 * 自动填写商品信息
 *  
 */
export const textToShopinfo = (text, callback) => {
  Net.get('/text/to_shop_info', {
    text
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, false, '')
}

/**
 * 自动填写地址信息
 *  
 */
export const textToAddressInfo = (text, callback) => {
  Net.get('/text/toaddress', {
    text
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, false, '')
}



/**
 * 开单提交订单
 * supplier_id,  //供应商id
 * p_c_b //收件人省市区
 * address,//收件人详细地址
 * name,//收件人名称
 * mobile,//收件人手机
 * earnest,//定金
 * sender_name,//发件人名称
 * sender_mobile,//发件人姓名
 * money_on_delivery,//代收货款
 * pay_state,//支付状态（1 支付，0 未支付）
 * items,//商品列表
 * is_cod,//是否为代收货款
 */
export const orderSubmit = (supplier_id, p_c_d, address, name, mobile, earnest, sender_name, sender_mobile, money_on_delivery, items, is_cod, memo, formId, callback) => {
  Net.post('/order/order', {
    supplier_id,
    p_c_d,
    address,
    name,
    mobile,
    earnest,
    sender_name,
    sender_mobile,
    money_on_delivery,
    items,
    is_cod,
    memo,
    formId
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
}


/**
 * 获取订单列表
 *  1:未处理 2:待发货 3：已发货
 */
export const getOrders = (state, page, proxy_id, callback) => {
  Net.get('/order/orders', {
    state,
    page,
    proxy_id
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
}



/**
 * 发货，预览订单信息 
 */
export const getforsendInfo = (oid, callback) => {
  Net.get('/order/order/forsend', {
    oid
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
}


/**
 * 发货
 */
export const delivery = (my_order_id, money, express_no, formId, deliver_option, callback) => {
  Net.post('/order/delivery', {
    my_order_id,
    money,
    express_no,
    formId,
    deliver_option
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '发货中...')
}



/**
 * 获取订单详情
 */
export const getOrderDetail = (my_order_id, callback) => {
  Net.get('/order/order/for_express_done', {
    my_order_id
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
}



/**
 * 下单发送给上级
 */
export const downOrder = (my_order_id, supplier_id, money, memo, formId, callback) => {
  Net.post('/order/transmit', {
    my_order_id,
    supplier_id,
    money,
    memo,
    formId
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '发送中...')
}




/**
 * 【分享】获取订单详情
 */
export const getOrderInfoForShare = (token, order_id, mobile, formId, callback) => {
  Net.get('/order/forshare', {
    token,
    order_id,
    mobile,
    formId
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
}



/**
 * 删除订单
 */
export const delOrder = (order_id, state, callback) => {
  debugger;
  Net.post('/order/delete', {
    order_id,
    state
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '删除中...')
}

/**
 * 作废订单
 */
export const trashOrder = (order_id, state, callback) => {
  Net.post('/order/trash', {
    order_id,
    state
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '操作中...')
}

/**
 * 获取注册信息初始化
 */
export const getRegisterInit = (callback) => {
  Net.get('/user/regist', {}, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
}


/**
 * 注册
 */
export const subRegister = (i, t, name, team_members, order_per_day, pro_cat, mobile, verifyCode, address, action, callback) => {
  Net.post('/user/regist', {
    i,
    t,
    name,
    team_members,
    order_per_day,
    pro_cat,
    mobile,
    verifyCode,
    address,
    action
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
}

/**
 * 获取验证码
 */
export const getCode = (mobile, action, callback) => {
  Net.post('/mobile/sms', {
    mobile,
    action
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '获取中...')
}


/**
 * 添加打印机
 */
export const addPrinter = (printerName, seriano, callback) => {
  Net.post('/printer', {
    printerName,
    seriano
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '连接中...')
}

/**
 * 删除打印机
 */
export const delPrinter = (id, callback) => {
  Net.post('/printer/del', {
    id
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '删除中...')
}

/**
 * 获取打印机列表
 */
export const getPrinters = (id, callback) => {
  Net.get('/printer/printers', {
    id
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
}

/**
 * 获取打印机状态
 */
export const getPrinterState = (id, callback) => {
  Net.get('/printer/printer', {
    id
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
}



/**
 * 获取打印温馨提示
 */
export const getPrinterHint = (callback) => {
  Net.get('/printer/hint', {}, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
}


/**
 * 打印
 */
export const printerSend = (my_order_id, callback) => {
  Net.post('/printer/print', {
    my_order_id
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '打印中...')
}



/**
 * 获取用户订单列表
 */
export const getUserOrder = (state, callback) => {
  Net.get('/buyer/orders', {
    state
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
}




/**
 * 获取帐目信息
 */
export const getReportFormInfo = (callback) => {
  Net.get('/account/balances', {}, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
}


/**
 * 获取指定月份帐目信息
 */
export const getReportFormInfoForDate = (month, callback) => {
  Net.get('/account/orders', {
    month
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
}

/**
 * 修改用户信息前  获取用户信息
 */
export const getUserInfo = (callback) => {
  Net.get('/user/info', {}, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
}


/**
 * 修改用户信息
 */
export const editUserInfo = (name, mobile, address, team_name,af_address,af_memo, formId, callback) => {
  Net.post('/user/info', {
    name,
    mobile,
    address,
    team_name,
    af_address,
    af_memo,
    formId
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '提交中...')
}



/**
 * 获取添加快递公司初始选择信息
 */
export const getexpressinit = (callback) => {
  Net.get('/express/coms/list', {}, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
}


/**
 * 保存添加的快递公司
 * cod 代收货款账号
 * month_code  月结账号
 * customer_name  面单账号
 * customer_pwd 面单密码
 */
export const saveExpress = (id, code, tmpl_id, month_code, customer_name, customer_pwd, cod, callback) => {
  Net.post('/express/coms', {
    id,
    code,
    tmpl_id,
    month_code,
    customer_name,
    customer_pwd,
    cod
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '提交中...')
}



/**
 * 获取快递公司列表
 */
export const getExpressList = (id, callback) => {
  Net.get('/express/coms', {
    id
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
}


/**
 * 删除快递公司 
 */
export const delExpress = (id, callback) => {
  Net.post('/express/coms/del', {
    id,
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '删除中...')
}



/**
 * 获取操作指南列表
 */
export const getZhiNanList = (callback) => {
  Net.get('/tutorial/videos', {}, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
}

/**
 * 获取token
 */
export const getToken = (jscode, callback) => {
  Net.get('/user/simplelogin', {
    jscode
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, false, '')
}


/**
 * 获取批量打印订单列表
 */
export const getBatchOrders = (callback) => {
  Net.get('/order/ordersforprint', {}, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
}

/**
 * 批量打印 
 */
export const batchPrinter = (ids, callback) => {
  Net.post('/printer/batchprint', {
    ids,
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '请求中...')
}


/**
 * 获取批量接单订单列表
 */
export const getBatchAcceptOrders = (callback) => {
  Net.get('/order/batch_accept', {}, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
}

/**
 * 批量接单
 */
export const batchAccept = (ids, callback) => {
  Net.post('/order/batch_accept', {
    ids,
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '请求中...')
}



/**
 * 提醒发货 
 */
export const tiXingFaHuo = (my_order_id, callback) => {
  Net.post('/order/urge_deliver', {
    my_order_id,
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '请求中...')
}



/**
 * 手机号登录 
 */
export const mobileLogin = (mobile, verifyCode, action, token, callback) => {
  Net.get('/user/mobile_login', {
    mobile,
    verifyCode,
    action,
    token
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '请求中...')
}

/**
 * 退出手机登录 
 */
export const exitLogin = (callback) => {
  Net.get('/user/mobile_exitlogin', {}, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '正在退出...')
}



/**
 * 接单 
 */
export const JieDan = (my_order_id, delay,memo, callback) => {
  Net.post('/order/accept', {
    my_order_id,
    delay,
    memo
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '接单中...')
}


/**
 * 拒绝接单
 */
export const JuJueJieDan = (my_order_id, reason, callback) => {
  Net.post('/order/reject', {
    my_order_id,
    reason,
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '操作中...')
}


/**
 * 获取批量打印订单列表
 */
export const orderSearch = (keywork, state, page, callback) => {
  Net.get('/order/search', {
    keywork,
    state,
    page
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '搜索中...')
}

/**
 * 修改备注
 */
export const editRemark = (order_id, item_id, memo, callback) => {
  Net.post('/order/item/memo', {
    order_id,
    item_id,
    memo,
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '操作中...')
}

/**
 * 客户提醒发货
 */ 
export const buyertixingfahuo = (order_id,callback) => {
  Net.post('/order/buyer_urge_deliver', {
    order_id, 
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '操作中...')
}



/**
 * 获取售后列表 
 */
export const getaftersalelist = (tab_id, seller_id, page,callback) => {
  Net.get('/afservices/list', { tab_id, seller_id, page}, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
}

/**
 * 获取创建售后初始化信息 
 */
export const getaftersaleinitinfo = (callback) => {
  Net.get('/afservices/create', { }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
}


/**
 * 创建售后
 */
export const aftersaleCreate = (item_name, aftype_id, supplier_id, dealer_address,memo, callback) => {
  Net.post('/afservices/store', {
    item_name, aftype_id, supplier_id, dealer_address, memo
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '操作中...')
} 

/**
 * 买家查看售后并编辑界面 
 */
export const getAftersaleInfo = (afservice_id,token,callback) => {
  Net.get('/afservices/buyer/edit', { afservice_id,token}, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
}


/**
 * 买家提交售后
 */
export const buyersubaftersale = (afservice_id, problem, buyer_name, buyer_mobile, buyer_address, express_no, fromId,token, callback) => {
  Net.post('/afservices/buyer/update', {
    afservice_id, problem, buyer_name, buyer_mobile, buyer_address, express_no, fromId, token
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '提交中...')
}  


/**
 * 买家查看售后并编辑界面 
 */
export const getAftersaleDetailView = (afservice_id, callback) => {
  Net.get('/afservices/show', { afservice_id }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
} 



/**
 * 售后签收，及标记完成发货
 */
export const aftersalehandle = (afservice_id, express_no,formId, callback) => {
  Net.post('/afservices/update', {
    afservice_id, express_no, formId
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '操作中...')
} 

/**
 * 获取备注 
 */
export const getMemos = ( callback) => {
  Net.get('/memos', {  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
} 

/**
 * 删除中
 */
export const memosDel = (callback) => {
  Net.post('/memos/del', { 
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '操作中...')
} 



/**
 * 获取备注 
 */
export const searchAfterSale = (keyword,callback) => {
  Net.get('/afservices/search', { keyword}, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
}  

/**
 * 售后打印中
 */
export const afterPrint = (afservice_id,callback) => {
  Net.post('/afservices/print', {
    afservice_id
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '打印中...')
}  


/**
 * 获取物流信息 
 */
export const getafexpressinfo = (afservice_id, callback) => {
  Net.get('/afservices/express_info', { afservice_id }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
}   
 


/**
 * 获取售后人员列表 
 */
export const getafuserlist = (tab_id, callback) => {
  Net.get('/afservices/af_statics', { tab_id }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
}   

/**
 * 提醒处理售后
 */
export const tiXingChuLi = (afservice_id, callback) => {
  Net.post('/afservices/notify_dealer', {
    afservice_id
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '请求中...')
}  
 

/**
 * 获取我的订单人员列表 
 */
export const getownerslist = (state, callback) => {
  Net.get('/order/owners', { state }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
}   

/**
 * 创建邀请下单链接 id 
 */
export const createInviteCode = (id,callback) => {
  Net.get('/user/supplier_info', { id }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
}   


/**
 * 获取物流信息 
 */
export const getorderexpressinfo = (order_id, callback) => {
  Net.get('/order/express_info', { order_id }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
}

 